package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.pojo.dto.GoodsOrdersQueryDto;
import com.example.pojo.entity.GoodsOrders;
import com.example.pojo.vo.GoodsOrdersQueryVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;

/**
 * 宠物用品订单 mapper 层
 */
@Mapper
public interface GoodsOrdersMapper extends BaseMapper<GoodsOrders> {

    /**
     * 分页查询宠物用品订单
     *
     * @param pageObject MybatisPlus 分页对象
     * @param dto 条件
     * @return 分页结果
     */
    IPage<GoodsOrdersQueryVo> pageQuery(@Param("page") IPage<GoodsOrdersQueryVo> pageObject, @Param("dto") GoodsOrdersQueryDto dto);

    /**
     * 根据宠物店id，计算宠物用品销售额
     *
     * @param shopId 宠物店id
     * @return 宠物用品销售额
     */
    @Select("select ifnull(sum(goods_orders.price * goods_orders.goods_number), 0) from goods_orders where goods_orders.shop_id = #{shopId} and goods_orders.status = '已完成'")
    BigDecimal countAmountByShopId(@Param("shopId") Integer shopId);

    /**
     * 统计宠物用品销售额
     *
     * @param shopId 宠物店id
     * @param start 开始时间
     * @param end 结束时间
     * @return 宠物用品销售额
     */
    BigDecimal countSale(@Param("shopId") Integer shopId, @Param("start") String start, @Param("end") String end);
}
